package com.example.jyjava.controller;

import com.alibaba.fastjson.JSON;
import com.example.jyjava.bean.Report;
import com.example.jyjava.dao.ReportDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;

@RestController
@RequestMapping("/report")
public class ReportController {
    @Autowired
    private ReportDao reportDao;

    @RequestMapping("/addReport")
    public String addReport(@RequestBody Report report){
        String falg = "400";
        report.setCreatTime(new Date());
        int i = reportDao.addReport(report);
        HashMap<String, Object> res = new HashMap<>();  //map封装

        if (i > 0){
            falg = "200";
            res.put("flag",falg);
            res.put("report",i);
        }else{
            res.put("flag",falg);
        }
        String s = JSON.toJSONString(res);
        return s;
    }
}
